package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanhua.server.mapper.UserInfoMapper;
import com.tanhua.server.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    public UserInfo queryUserInfoByUserId(Long id) {
        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInfo::getUserId,id);
        return userInfoMapper.selectOne(queryWrapper);
    }

    public List<UserInfo> queryRecommendationInfo(LambdaQueryWrapper<UserInfo> wrapper) {
        return userInfoMapper.selectList(wrapper);
    }

    public List<UserInfo> queryUserInfoList(LambdaQueryWrapper<UserInfo> wrapper) {
        return userInfoMapper.selectList(wrapper);
    }

    public List<UserInfo> queryUserInfoList(LambdaQueryWrapper<UserInfo> wrapper, IPage<UserInfo> iPage) {
        return userInfoMapper.selectPage(iPage,wrapper).getRecords();
    }

    public Boolean updateUserInfoByUserId(UserInfo userInfo) {
        LambdaQueryWrapper<UserInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserInfo::getUserId,userInfo.getUserId());
        return userInfoMapper.update(userInfo,wrapper) > 0;
    }
}
